#ifndef IMAGE_H
#define IMAGE_H


class Image
{
public:
	Image();
	Image(unsigned int newWidth, unsigned int newHeight);
	~Image();

	void SetComponent(unsigned int x, unsigned int y, unsigned char intensity);
	unsigned char GetComponent(unsigned int x, unsigned int y) const;

	unsigned char& operator()(unsigned int x, unsigned int y);

	virtual void ReadFromFile(const char* filename);
	virtual void WriteToFile(const char* filename);

	void ReadRawFromFile(const char* filename);
	void WriteRawToFile(const char* filename);

	void SetDimension(unsigned int newWidth, unsigned int newHeight);

	Image* NextSegment();
	void UpdateWithSegment();
	void InitializeSegment(unsigned int blockWidth, unsigned int blockHeight);


	unsigned int GetWidth() const 
	{ 
		return width; 
	}

	unsigned int GetHeight() const
	{ 
		return height; 
	}

	const unsigned char* GetConstData() const
	{
		return data;
	}

	unsigned char* GetData()
	{
		return data;
	}

	unsigned int GetOriginX()
	{
		return originX;
	}

	unsigned int GetOriginY()
	{
		return originY;
	}


protected:

private:
	Image(const Image& rhs); // copy constructor not implemented yet

	void ClearSegment();
	void ClearImage();
	void Clear();

	unsigned char *data;
	unsigned int width, height;
	unsigned int originX, originY;

	Image *segment;

};

#endif //IMAGE_H